<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>改变一个包含在iframe中的文档的背景颜色</title>
</head>

<body>
    <iframe id="myframe" src="demo_iframe.htm">
        <p>你的浏览器不支持iframes。</p>
    </iframe>
    <br><br>
    <input type="button" onclick="changeStyle()" value="修改背景颜色">
    <script>
        function changeStyle() {
            var x = document.getElementById("myframe");
            var y = (x.contentWindow || x.contentDocument);
            if (y.document) y = y.document;
            y.body.style.backgroundColor = "#0000ff";
        }
    </script>
</body>

</html>